package com.molin.exceptionTest;

public class Demo5 {
    public static void main(String[] args) {
//        int[] arr={1,2,3,4,5};
        int arr[] = null;
        try {
            printArr(arr);//接受到异常，需要调用者处理。调用者不处理，交给JVM虚拟机处理

        } catch (NullPointerException ex) {
            System.out.println("空指针异常,参数不能为null");
        }


    }

    private static void printArr(int[] arr) throws NullPointerException {
        if (arr == null) {
            throw new NullPointerException();
        }

        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
    }
}
